package edu.ues21.tcs.ecommerce2011.mvc.dao;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.Properties;
/**
 * @author eandre fmantaras juanini
 * @etiqueta Genera la conexion a la BD de MySql.
 */
public class MySqlDb {
	
	/**
	 * Inicializa el constructor con una conexion a la BD
	 * @return una conexion si funciona
	 * @return un null si falla la conexion
	 * 
	 */
	private static Properties pr;
	static {
		try {
			pr= new Properties();
			pr.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("jdbc.properties"));
			}catch(Exception e){
				
			}
	}
	
	public static Connection getConnection(){
		Connection conexion=null;
                try {
			Class.forName(pr.getProperty("jdbc.driverClassName"));
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		}
		try {
			conexion = DriverManager.getConnection(pr.getProperty("jdbc.url"),pr.getProperty("jdbc.username"),pr.getProperty("jdbc.password"));
		} catch (SQLException e) {
			//e.printStackTrace();
			return null;
		}
		return conexion;
	}
	
}
